<?php
class ModelPagePage extends Model {
	public function getPage($page_id) {
		$sql = "SELECT DISTINCT * FROM " . DB_PREFIX . "page p LEFT JOIN " . DB_PREFIX . "page_information pi ON (p.page_id = pi.page_id) LEFT JOIN " . DB_PREFIX . "page_to_conference p2c ON (p.page_id = p2c.page_id) WHERE p.page_id='" . (int)$page_id . "' AND pi.language_id='" . (int)$this->config->get('config_language_id') . "' AND p2c.conf_id='" . (int)$this->config->get('config_conf_id') . "' AND p.status='1'";
		$query = $this->db->query($sql);
		return $query->row;
	}
	
	//父页面的下一层子页面
	public function getPagesByParentId($parent_id = 0) {
		$sql = "SELECT * FROM " . DB_PREFIX . "page p LEFT JOIN " . DB_PREFIX . "page_information pi ON (p.page_id = pi.page_id) LEFT JOIN ". DB_PREFIX . "page_to_conference p2c ON (p.page_id=p2c.page_id) WHERE p.parent_id='" . (int)$parent_id . "' AND pi.language_id='" . (int)$this->config->get('config_language_id') . "' AND p2c.conf_id='" . $this->config->get('config_conf_id') . "' and p.status='1' ORDER BY p.sort_order, LCASE('pi.title')";
		$query = $this->db->query($sql);
		return $query->rows; 
	}
	
	//页面所有层次的子页面
	public function getPagesByPageId($page_id) {
		 $page_data = array();
		 
		 $page_query = $this->db->query("SELECT page_id FROM ". DB_PREFIX . "page WHERE parent_id='" . (int)$page_id . "'");
		 
		 foreach($page_query->rows as $page) {
		 	$page_data[] = $page['page_id'];
		 	
		 	$children = $this->getPagesByPageId($page['page_id']);
		 	
		 	if($children) {
		 		$page_data = array_merge($children, $page_data);
		 	}
		 }
		 
		 return $page_data;
	}
	
	
	public function getTotalPages($parent_id = 0) {
		
	}
	
}